/**
 * 文章浏览页面JS
 *
 **/



jQuery( function(){

	var $ = jQuery;


	//用户点击顶部的导航栏，需要改变当前请求文章类型
	var navControl = {

		itemClass : 'nav-item', 
		itemSelectedClass : 'nav-item-active', 

		init : function(){
			this.$el = $('#nav-list-con');
			this._setupEvent();
		}, 
		_setupEvent : function(){

			var that = this;
			this.$el.on( 'click', '.' + this.itemClass, function(e){
				var $el = $( e.target );
				if( $el.hasClass(that.itemSelectedClass) ){
					return;
				}
				var type = $el.data('type');
				if( type ){

					location.href = '/#type=' + encodeURIComponent(type);
				}
			});
		}, 

		render : function( state ){
			var type = state.filterType;
			this.$el.find('.' + this.itemClass ).removeClass( this.itemSelectedClass );
			var $target = this.$el.find( '.' + this.itemClass + '[data-type="' + type + '"]').addClass( this.itemSelectedClass );
		}
	};




	//返回顶部按钮
	$('#back-top').click( function(){
		window.scrollTo( 0, 0 );
	});

	//顶部导航栏控制器
	navControl.init();
	

});